package com.ruoyi.jiajia.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.JiajiaProxyApplication;
import com.ruoyi.system.service.IJiajiaProxyApplicationService;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 代理申请记录Controller
 * 
 * @author ruoyi
 * @date 2025-03-04
 */
@Controller
@RequestMapping("/jiajia/jiajiaProxyApplication")
public class JiajiaProxyApplicationController extends BaseController
{
    private String prefix = "jiajia/jiajiaProxyApplication";

    @Autowired
    private IJiajiaProxyApplicationService jiajiaProxyApplicationService;

    @RequiresPermissions("jiajia:jiajiaProxyApplication:view")
    @GetMapping()
    public String jiajiaProxyApplication()
    {
        return prefix + "/jiajiaProxyApplication";
    }

    /**
     * 查询代理申请记录列表
     */
    @RequiresPermissions("jiajia:jiajiaProxyApplication:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(JiajiaProxyApplication jiajiaProxyApplication) {
        startPage();
        List<JiajiaProxyApplication> list = jiajiaProxyApplicationService.selectJiajiaProxyApplicationList(jiajiaProxyApplication);
        return getDataTable(list);
    }

    /**
     * 导出代理申请记录列表
     */
    @RequiresPermissions("jiajia:jiajiaProxyApplication:export")
    @Log(title = "代理申请记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(JiajiaProxyApplication jiajiaProxyApplication) {
        List<JiajiaProxyApplication> list = jiajiaProxyApplicationService.selectJiajiaProxyApplicationList(jiajiaProxyApplication);
        ExcelUtil<JiajiaProxyApplication> util = new ExcelUtil<JiajiaProxyApplication>(JiajiaProxyApplication.class);
        return util.exportExcel(list, "代理申请记录数据");
    }

    /**
     * 新增代理申请记录
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存代理申请记录
     */
    @RequiresPermissions("jiajia:jiajiaProxyApplication:add")
    @Log(title = "代理申请记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(JiajiaProxyApplication jiajiaProxyApplication) {

        return   AjaxResult.success(jiajiaProxyApplicationService.insertJiajiaProxyApplication(jiajiaProxyApplication));

    }

    /**
     * 修改代理申请记录
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        JiajiaProxyApplication jiajiaProxyApplication = jiajiaProxyApplicationService.selectJiajiaProxyApplicationById(id);
        mmap.put("jiajiaProxyApplication", jiajiaProxyApplication);
        return prefix + "/edit";
    }

    /**
     * 修改保存代理申请记录
     */
    @RequiresPermissions("jiajia:jiajiaProxyApplication:edit")
    @Log(title = "代理申请记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(JiajiaProxyApplication jiajiaProxyApplication) {
        return toAjax(jiajiaProxyApplicationService.updateJiajiaProxyApplication(jiajiaProxyApplication));
    }

    /**
     * 删除代理申请记录
     */
    @RequiresPermissions("jiajia:jiajiaProxyApplication:remove")
    @Log(title = "代理申请记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(jiajiaProxyApplicationService.deleteJiajiaProxyApplicationByIds(ids));
    }

    @PostMapping("/audit")
    @ResponseBody
    public AjaxResult audit(JiajiaProxyApplication jiajiaProxyApplication) {
        return AjaxResult.success(jiajiaProxyApplicationService.auditJiajiaProxyApplication(jiajiaProxyApplication));
    }


    @ApiOperation("绘图")
    @GetMapping("/mapPoints/{id}")
    public String mapPoints(@PathVariable("id") Long id, ModelMap mmap) {
        JiajiaProxyApplication jiajiaProxyApplication = jiajiaProxyApplicationService.selectJiajiaProxyApplicationById(id);
        mmap.put("latitude", jiajiaProxyApplication.getLatitude());
        mmap.put("longitude", jiajiaProxyApplication.getLongitude());
        mmap.put("id", jiajiaProxyApplication.getId());
        mmap.put("jiajiaProxyApplication", jiajiaProxyApplication);

        return  prefix + "/edit1";
    }

    @ApiOperation("绘图")
    @PostMapping("examine")
    @ResponseBody
    public AjaxResult examine(JiajiaProxyApplication jiajiaProxyApplication) {

        jiajiaProxyApplicationService.examine(jiajiaProxyApplication);

        return  AjaxResult.success();
    }
}
